package com.dc.toolkit.guava.concurrent;

import com.google.common.util.concurrent.Atomics;
import org.junit.Test;

import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.AtomicReferenceArray;

/**
 * Description: Guava_Atomics 测试类
 * @author: gdc
 * @date: 2021/10/22
 * @version 1.0
 */
public class AtomicsTest {


    /**
     * 测试           创建一个AtomicReference实例
     */
    @Test
    public void test_newReference(){
        AtomicReference<String> reference = Atomics.newReference();
        reference.set("000");
        System.out.println(reference.get());

        // -------------------------------------------------------------

        AtomicReference<AtomicsTest> reference2 = Atomics.newReference(new AtomicsTest());
        System.out.println(reference2.toString());
    }

    /**
     * 测试           创建一个AtomicReferenceArray实例
     */
    @Test
    public void test_newReferenceArray(){
        AtomicReferenceArray<Integer> referenceArray = Atomics.newReferenceArray(5);
        referenceArray.set(0, 11);
        referenceArray.set(1, 22);
        System.out.println(referenceArray.toString());

        // -------------------------------------------------------------

        AtomicReferenceArray<Object> referenceArray2 = Atomics.newReferenceArray(new String[]{"a", "b", "c"});
        System.out.println(referenceArray2.toString());
    }

}
